package edu.ues21.tcs.ecommerce2011.mvc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import edu.ues21.tcs.ecommerce2011.mvc.dao.ListaPrecioDAO;

/**
 * 
 * @author Acunia Marco.
 */
public class DeleteListaPreciosController extends HttpServlet {

	ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
			"/BeanLocations.xml");

	ListaPrecioDAO mDao = (ListaPrecioDAO) appContext.getBean("listaprecioDAO");

	private static final long serialVersionUID = 1L;

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String id = request.getParameter("id");
		System.out.println("++++++++++++++++++++++ " + id);

		if (id != null) {

			Integer idint = Integer.parseInt(id);
			mDao.delete(idint);
		}
		response.sendRedirect("listarLP.do");
	}

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		processRequest(request, response);

	}

	@Override
	public String getServletInfo() {
		return "Short description";
	}// </editor-fold>

}
